package HomeWork;

class Solution3 {
    public int removeDuplicates(int[] nums) {
        int ret = 0;
        for (int i = 0; i < nums.length; i++) {
            int val = nums[i];
            int Key = i + 1;
            for (int j = i + 1; j < nums.length; j++) {
                if(nums[j] != val) {
                    nums[Key] = nums[j];
                    Key++;
                }
            }
        }
        //0 1 2 3 4 5 5
        for (int i = nums.length - 1; i >= 0; i--) {
            //如果一个数在前面都没出现过，就可以加一
            int flag = 0;
            for (int j = 0; j < i; j++) {
                if(nums[j] == nums[i]) {
                    flag = 1;
                    break;
                }
            }
            if(flag == 1)
                ret++;
        }
        return nums.length-ret;
    }
}
public class Test_3 {
    public static void main(String[] args) {
        Solution3 s = new Solution3();
        int[] x ={1,1,1,2,2,3,4,5};
        System.out.println(s.removeDuplicates(x));
    }
}
